package com.dq.domain.message.oneself;

import com.alibaba.fastjson.JSONObject;
import com.dq.vo.baseVo.VO;
import com.dq.domain.orders.OrgOrder;
import com.dq.utils.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;

/**
 * @author liuhui
 * @date 2019/11/22 0022 10:27:17
 */
@Data
@Entity
@ApiModel("采购审批消息")
public class ApprovalMessage extends Message {

    @ApiModelProperty("采购单")
    @ManyToOne
    protected OrgOrder orgOrder;

    @Data
    @ApiModel("视图")
    public static class Vo implements VO {
        protected Long id;

        @ApiModelProperty("未读/已读")
        public String messageStatusEn;
        @ApiModelProperty("未读/已读")
        public String messageStatusCn;
        @ApiModelProperty("消息类型")
        public String messageTypeEn;
        @ApiModelProperty("消息类型")
        public String messageTypeCn;

        @ApiModelProperty("创建时间")
        public String createTime;

        @ApiModelProperty("采购单信息")
        public JSONObject orgOrderJson;
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.id = this.id;

        vo.messageStatusEn = this.getMessageStatus().toString();
        vo.messageStatusCn = this.getMessageStatus().name;
        vo.messageTypeEn = this.getMessageType().toString();
        vo.messageTypeCn = this.getMessageType().name;

        vo.createTime = fmt(this.createTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("sysDeptId", this.orgOrder.getOrg() == null ? null : this.orgOrder.getOrg().getId());
        jsonObject.put("sysDeptName", this.orgOrder.getOrg() == null ? null : this.orgOrder.getOrg().getSimpleName());
        jsonObject.put("ordersNo", this.orgOrder.getOrdersNo());
        // 采购时间
        jsonObject.put("time", fmt(this.createTime, TimeUtil.YYYY_MM_DD_HH_MM_SS));
        jsonObject.put("orgOrderStatusEn", this.getOrgOrder().getOrgOrderStatus().toString());
        jsonObject.put("orgOrderStatusCn", this.getOrgOrder().getOrgOrderStatus().name);
        jsonObject.put("price", this.getOrgOrder().getPrice());
        vo.orgOrderJson = jsonObject;

        return vo;
    }

}
